<template>
  <div>
    <el-dialog :title="title"
      :visible.sync="dialogVisible"
      width="50%"
      top="5vh"
      @close.native="cancel"
      :close-on-click-modal="false">
      <el-form ref="ruleForm"
        :model="form"
        :rules="rules"
        label-width="120px">
        <el-form-item label="内容："
          prop="content">
          <el-input v-model="form.content"
            type="textarea"
            rows="7"
            placeholder="请输入内容" />
        </el-form-item>
      </el-form>
      <div slot="footer"
        class="dialog-footer">
        <el-button type="primary"
          @click="submitForm">确 定</el-button>
        <el-button @click="
          cancel">取 消</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import { addComment } from '@/api/publishManage.js'
export default {
  data() {
    return {
      dialogVisible: false,
      title: '',
      form: {
        content: ''
      },
      rules: {
        content: [
          { required: true, message: '内容不能为空！', trigger: 'blur' }
        ]
      }
    }
  },

  created() {},
  methods: {
    show(obj) {
      this.dialogVisible = true
      this.title = obj.title
      this.form.articleId = obj.data.articleId
    },
    submitForm() {
      this.$refs['ruleForm'].validate(valid => {
        if (valid) {
          addComment(this.form).then(() => {
            this.cancel()
          })
        } else {
          return false
        }
      })
    },
    cancel() {
      this.form = this.$options.data().form
      this.$refs.ruleForm.clearValidate()
      this.title = ''
      this.dialogVisible = false
      this.$emit('closeComment')
    }
  }
}
</script>

<style lang="less" scoped>
</style>